package cn.rokhdelar.umbrsapi.management.controller;

import cn.rokhdelar.umbrsapi.management.entity.LoginDTO;
import cn.rokhdelar.umbrsapi.management.service.AuthenticationService;
import cn.rokhdelar.umbrsapi.management.service.CaptchaService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/auth")
public class AuthenticationController {
    private final AuthenticationService authenticationService;
    private final CaptchaService captchaService;

    public AuthenticationController(AuthenticationService authenticationService, CaptchaService captchaService) {
        this.authenticationService = authenticationService;
        this.captchaService = captchaService;
    }

    @GetMapping(value = "/kaptcha")
    public ResponseEntity<Map<String, String>> getCaptcha() {
        return ResponseEntity.ok(captchaService.getCaptcha());
    }
    @PostMapping(value = "/login")
    public Map<String, Object> login(@RequestBody LoginDTO loginDTO) {
        return authenticationService.login(loginDTO);
    }
}
